/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    io.h
 *  @brief   IO header file
 *  @version v1.0
 *  @date    03. Apr. 2023
 ****************************************************************/

#ifndef __IO_H__
#define __IO_H__

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/* IO definitions (access restrictions to peripheral registers) */
#ifdef __cplusplus
#define     __I        volatile          /*!< Defines 'read only' permissions */
#else
#define     __I        volatile const    /*!< Defines 'read only' permissions */
#endif
#define     __O        volatile          /*!< Defines 'write only' permissions */
#define     __IO       volatile          /*!< Defines 'read / write' permissions */

/* following defines should be used for structure members */
#define     __IM       volatile const    /*! Defines 'read only' structure member permissions */
#define     __OM       volatile          /*! Defines 'write only' structure member permissions */
#define     __IOM      volatile          /*! Defines 'read / write' structure member permissions */

#define ARRAY_SIZE(array)               (sizeof(array)/sizeof(array[0]))
#define OFFSETOF(base, type, member)    (base + offsetof(type, member))

/* Bit field operate*/
#define REG64(addr)                     (*(volatile uint64_t *)(addr))
#define REG32(addr)                     (*(volatile uint32_t *)(addr))
#define REG16(addr)                     (*(volatile uint16_t *)(addr))
#define REG8(addr)                      (*(volatile uint8_t  *)(addr))

typedef uint32_t reg_t;

#ifdef __cplusplus
}
#endif

#endif /* __IO_H__ */
